public class GetDecimalValue {
    //求二级制链表的十进制值
    //递归|栈(原理:先进后出)
    int n = 0;
    public int getDecimalValue1(ListNode head){
        if(head==null){
            return 0;
        }
        int num = getDecimalValue1(head.next);
        return num+(int)(head.val*Math.pow(2,n++));
    }
    //位运算
    public int getDecimalValue2(ListNode head) {
        int result = 0;
        while(head!=null){
            result = (result << 1)+head.val;
            head = head.next;
        }
        return result;
    }
    //余数反推
    public int getDecimalValue3(ListNode head) {
        int result = 0;
        while(head!=null){
            result = result*2+head.val;
            head = head.next;
        }
        return result;
    }
}
